package time_20230810;

import java.util.Scanner;

/**
 * @author lizhen
 * @date 2023/8/10 15:36
 */

/**
 * 9.回文数
 */
public class IsPalindrome {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请您输入正整数：");
        int a = sc.nextInt();
        boolean result = isPalindrome(a);
        System.out.println("是否是回文数：" + result);
    }

    public static boolean isPalindrome(int a){
        if (a < 0 || (a % 10 == 0 && a != 0)){
            return false;
        }

        int revertedNumber = 0;
        while (a > revertedNumber){
            revertedNumber = revertedNumber * 10 + a % 10;
            a /= 10;
        }

        return a == revertedNumber || a == revertedNumber / 10;
    }
}
